package com.ztools.pc.controller.card;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ztools.common.model.pc.card.CardRechargeRecord;
import com.ztools.common.util.common.PageUtil;
import com.ztools.common.util.common.Result;
import com.ztools.pc.service.card.CardRechargeRecordService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author seeTools
 * @since 2023-06-30
 */
@RestController
@RequestMapping("/card/recharge/record")
public class CardRechargeRecordController {

    @Resource
    private CardRechargeRecordService cardRechargeRecordService;

    @PostMapping("/list")
    public Result findList(@RequestBody PageUtil<CardRechargeRecord> pageUtil) {
        Page<CardRechargeRecord> list = cardRechargeRecordService.findList(pageUtil);
        return list != null ? Result.success("查询成功").data(list) : Result.error();
    }

    @RequestMapping("/findByObject")
    public Result findByObject(@RequestBody CardRechargeRecord cardRechargeRecord) {
        List<CardRechargeRecord> list = cardRechargeRecordService.findByObject(cardRechargeRecord);
        return list != null ? Result.success("查询成功").data(list) : Result.error();
    }

    @RequestMapping("/update")
    public Result update(@RequestBody CardRechargeRecord cardRechargeRecord) {
        boolean b = cardRechargeRecordService.update(cardRechargeRecord);
        return b ? Result.success("修改成功") : Result.error();
    }

    @RequestMapping("/delete")
    public Result delete(@RequestBody CardRechargeRecord cardRechargeRecord) {
        boolean b = cardRechargeRecordService.delete(cardRechargeRecord);
        return b ? Result.success("删除成功") : Result.error();
    }

    @RequestMapping("/add")
    public Result add(@RequestBody CardRechargeRecord cardRechargeRecord) {
        boolean b = cardRechargeRecordService.save(cardRechargeRecord);
        return b ? Result.success("添加成功") : Result.error();
    }

    @RequestMapping("/recharge")
    public Result recharge(@RequestBody CardRechargeRecord cardRechargeRecord) {
        cardRechargeRecordService.recharge(cardRechargeRecord);
        return Result.success("充值成功");
    }

    @RequestMapping("/export")
    public void excel(HttpServletResponse response, @RequestBody CardRechargeRecord cardRechargeRecord) {
        cardRechargeRecordService.exportExcel(response, cardRechargeRecord);
    }
}
